package com.imjohn.util;

import net.sf.json.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class httpClient {
    public static String httpPostJson( JSONObject jsonObject){
    DefaultHttpClient httpClient = new DefaultHttpClient();
    String loginUrl = "http://172.30.154.111:8088/web/v1/login";
    String result = null;
    HttpPost post = new HttpPost(loginUrl);
    post.setHeader("content-type","application/json");
    StringEntity entity = new StringEntity(jsonObject.toString(),"UTF-8");
    post.setEntity(entity);
    try {
        HttpResponse response = httpClient.execute(post);
        result = EntityUtils.toString(response.getEntity(),"UTF-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

}
